from transformers import pipeline

try:
    # 指定正确的模型名称
    classifier = pipeline(
        "sentiment-analysis",
        model="distilbert-base-uncased-finetuned-sst-2-english"
    )

    # 单条文本测试
    result = classifier("I've been waiting for a HuggingFace course my whole life.")
    print("单条文本结果:", result)

    # 批量文本测试
    results = classifier([
        "I've been waiting for a HuggingFace course my whole life.",
        "I hate this so much!"
    ])
    print("批量文本结果:", results)

except Exception as e:
    print(f"模型加载或推理过程中出错: {e}")
    print("提示: 请确保网络连接正常，或尝试手动下载模型到本地")